package bite;

/**
 * Creared with IntelliJ IDEA.
 * Description:【Fibonacci数列】Fibonacci数列是这样定义的：
 * F[0] = 0
 * F[1] = 1
 * for each i ≥ 2: F[i] = F[i-1] + F[i-2]
 * 因此，Fibonacci数列就形如：0, 1, 1, 2, 3, 5, 8, 13, ...，在Fibonacci数列中的数我们称为Fibonacci数。给你一个N，你想让其变为一个Fibonacci数，每一步你可
 * 以把当前数字X变为X-1或者X+1，现在给你一个数N求最少需要多少步可以变为Fibonacci数。
 * User:yxd
 * Date:2022-03-30
 * Time:17:41
 */

import java.util.*;
public class Day7_1 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int first = 0;
        int second = 1;
        int three = 1;
        for(int i = 0;i < n;i ++){
            three = second + first;
            first = second;
            second = three;
            if(three >= n){
                break;
            }
        }
        int count = Math.min(second - n,n - first);
        System.out.println(count);
    }
}


